package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/get")
public class GetSession {
    @RequestMapping("/login")
    public String login(HttpServletRequest request) {
        // 切记一定要加 false,这表示有 session 就获取，没有不会创建
        HttpSession session = request.getSession(false);
        if (session != null && session.getAttribute("ylc") != null) {
            return "登录成功";
        } else {
            return "登录失败";
        }
    }
}